#include <iostream>

using namespace std;

// 先考虑用暴力

const int N = 1e5 + 10;

int q[N] = {};
int top = 0;

bool empty()
{
    return !top;
}

void push(int x)
{
    q[top++] = x;
}

int pop()
{
    return q[--top];
}

int query()
{
    return q[top - 1];
}

int main(void)
{
    int m, t, x;
    scanf("%d", &m);
    push(-1);
    while (m--)
    {
        scanf("%d", &x);
        t = pop();
        while (t >= x)
            t = pop();
        printf("%d ", t);
        push(t);
        push(x);
    }
}